package com.qf.bank.controller;


import com.qf.bank.employeeapi.po.Info;
import com.qf.bank.service.IInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author q
 * @since 2019-12-07
 */
@RestController
public class InfoController  {
    @Autowired
    private IInfoService iInfoService;
    /**
     *
     *
     *@auther 李成浩
     *@return java.util.List<com.qf.bank.employeeapi.po.Info>
     *@date 2019/12/7 10:43
     * 查询所有员工
     */
    @RequestMapping(value = "/findAllEmployee",method = RequestMethod.GET)
    public List<Info> findAll(){
        List<Info> all = iInfoService.list();
        return all;
    }
    /**
     *
     *
     *@auther 李成浩
     *@return com.qf.bank.employeeapi.po.Info
     *@date 2019/12/7 10:42
     * 根据Id查询员工
     */
    @RequestMapping(value = "/findById",method = RequestMethod.GET)
    public Info findById(@RequestParam("jobNumber") int jobNumber){
        Info byId = iInfoService.getById(jobNumber);
        return byId;
    }
    /**
     *
     *
     *@auther 李成浩
     *@return java.lang.Boolean
     *@date 2019/12/7 10:42
     * 根据id删除员工
     */
    @RequestMapping(value = "/deleteById/{jobNumber}",method = RequestMethod.DELETE)
    public Boolean deleteById(@PathVariable int jobNumber){
        if (jobNumber>0){
            Info byId1 = iInfoService.getById(jobNumber);
            if (byId1!=null){
                boolean byId2 = iInfoService.removeById(jobNumber);
                return byId2;
            }
            return false;
        }
        return false;
    }
    /**
     *
     *
     *@auther 李成浩
     *@return java.lang.Boolean
     *@date 2019/12/7 10:42
     * 根据id修改员工
     */
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    public Boolean updateEmployee(@RequestBody Info info){
        boolean save = iInfoService.updateById(info);
        return save;
    }
    /**
     *
     *
     *@auther 李成浩
     *@param  * @param null
     *@return
     *@date 2019/12/7 10:42
     * 增加员工
     */
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public boolean insert(@RequestBody Info info ){
       return iInfoService.save(info);
    }


}
